


// import { Bitmap, DisplayObject, GameEngine, TextField } from "./engine";


// export function add(a: number, b: number) {
//     return a + b;
// }

// const engine = new GameEngine();
// const sceneConfig = [
    
//     { type: 'textfield', id:"word",properties: { x: -1100, y: 30, color: '#ff0000', text: '姓名：马寞晗，学号：18081104，班级：180811，学院：信息学部软件学院，专业：数字媒体技术，课程：游戏引擎设计', alpha: 0.5 } },
    
//     { type: 'bitmap', id: "bitmap-1", properties: { x: -1560, y: 200, source: 'assets/photo17.png' } },
// ];

// let move: Move;
// let movephoto: MovePhoto;

// engine.start(['assets/photo17.png'], sceneConfig);

// engine.onStart = () => {
//     const word = engine.getDisplayObject('word') as TextField;
//     move = new Move(word, 160);
//     const bitmap = engine.getDisplayObject('bitmap-1') as Bitmap;
   
//     movephoto = new MovePhoto(bitmap,200);
  
// }

// engine.onUpdate = (duringTime) => {
//     move.update(duringTime);
//     movephoto.update(duringTime);
  

// }

// class Move {
//     private totalTime = 0;
//     private initialX: number = 0;
//     constructor(private displayObject: DisplayObject, private speedX: number) {
//         this.initialX = displayObject.x;
//     }

//     update(duringTime: number) {
//         this.totalTime += duringTime;
//         const s0 = this.initialX;
//         const v = this.speedX;
//         const t = this.totalTime / 1000;
//         const s = s0 + v * t;
//         if(s <= 1000){
//             this.displayObject.x = s;
//         }
//         else{
//             this.displayObject.x = -1100;
//             //this.update(duringTime);
//             //这里想做一个循环播放的效果，想用if判断+函数递归调用来实现
//             //但是不知道为什么不定义好move具体移动哪个对象就无法实现“循环”,递归调用后界面就什么都没有了
//             //必须要在这里重新定义move，非常麻烦
//             //肯定是我思路有问题，但是我想不出来别的方法了qwq......
//             const word = engine.getDisplayObject('word') as TextField;
//              move = new Move(word, 160);
//              move.update(duringTime);
//         }
        
//     }
// }


// class MovePhoto {
//     private totalTime = 0;
//     private initialX: number = 0;
//     constructor(private displayObject: DisplayObject, private speedX: number) {
//         this.initialX = displayObject.x;
//     }

//     update(duringTime: number) {
//         this.totalTime += duringTime;
//         const s0 = this.initialX;
//         const v = this.speedX;
//         const t = this.totalTime / 1000;
//         const s = s0 + v * t;
//         if(s <= 1000){
//             this.displayObject.x = s;
//         }
//         else{
//             this.displayObject.x = -1560;
//             const bitmap = engine.getDisplayObject('bitmap-1') as Bitmap;
//             movephoto = new MovePhoto(bitmap,200);
//             movephoto.update(duringTime);
//         }
        
//     }
// }

import { Bitmap, DisplayObject, GameEngine } from "./engine";


export function add(a: number, b: number) {
    return a + b;
}

const engine = new GameEngine();
const sceneConfig = {
    type: 'displayobjectcontainer', properties: {
        x: 0, y: 0, alpha: 0, rotation: 0, scaleX: 1, scaleY: 1
    },
    children: [
        {
            type: 'displayobjectcontainer', properties: {
                x: 100, y: 0, alpha: 1, rotation: 45, scaleX: 1, scaleY: 1
            }, children: [
                { type: 'rectangle', properties: { x: 150, y: 50, color: '#ff0000', alpha: 0.5 } },
                { type: 'textfield', properties: { x: 300, color: '#ff0000', text: '马寞晗', alpha: 0.5 } },
                { type: 'textfield', properties: { x: 300, y: 40, text: '18081104', alpha: 1 } },
                { type: 'bitmap', id: "bitmap-1", properties: { x: 0, y: 0, rotation: 0, source: 'assets/photo3.jpg', alpha: 1 } },
            ]
        }
    ]
}

let move: Move;

engine.start(['assets/photo3.jpg'], sceneConfig);
engine.onStart = () => {
    // const bitmap = engine.getDisplayObject('bitmap-1') as Bitmap;
    // bitmap.onClick = () => {
    //     // bitmap.alpha = .1;
    // }
    // move = new Move(bitmap, 60);
}

engine.onUpdate = (duringTime) => {
    // move.update(duringTime);
}

engine.onTick = () => {
    // move.tick();
}

class Move {
    private totalTime = 0;
    private initialX: number = 0;
    constructor(private displayObject: DisplayObject, private speedX: number) {
        this.initialX = displayObject.x;
    }

    update(duringTime: number) {
        this.totalTime += duringTime;
        const s0 = this.initialX;
        const v = this.speedX;
        const t = this.totalTime / 1000;
        const s = s0 + v * t;
        this.displayObject.x = s;
    }

    tick() {
        this.displayObject.x += 1;
    }
}